package com.cn.medicalcare.controller.frontservlet;

import com.cn.medicalcare.customtool.JsonTool;
import com.cn.medicalcare.pojo.News;
import com.cn.medicalcare.pojo.ProductCategory;
import com.cn.medicalcare.service.ProductCategoryService;
import com.cn.medicalcare.service.serviceimpl.ProductCategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getproductcategorysurvival.json")
public class ProductCategorySurvivalServlet extends HttpServlet {

    private ProductCategoryService productCategoryService= ProductCategoryServiceImpl.getInstance();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map<String, Object> map = new LinkedHashMap<>();
        try {
            List<ProductCategory> list = productCategoryService.selectProductCategoryAll();
            if (list != null && list.size() > 0) {
                map.put("status", 200);
                map.put("data", list);
            } else {
                map.put("status", 404);
            }
        } catch (Exception e) {
            map.put("status", 500);
        }
        resp.getWriter().print(JsonTool.toJson(map));
    }

}
